package serialization;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

@SuppressWarnings("serial")
public class StaticTransient implements Serializable{

	volatile int x1 = 0;
	transient int x2 = 0;
	static int x3 = 0;
	
	public static void main(String[] args) {
		StaticTransient staticTransient = new StaticTransient();
		staticTransient.x1 = 1;
		staticTransient.x2 = 2;
		StaticTransient.x3 = 3;
		
		try {
			FileOutputStream fos = new FileOutputStream(new File("output.txt"));
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject(staticTransient);
			oos.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		StaticTransient.x3 = 0;
		
		try {
			FileInputStream fis = new FileInputStream(new File("output.txt"));
			ObjectInputStream ois = new ObjectInputStream(fis);
			Object object = ois.readObject();
			System.out.println(object);
			ois.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		
	}
	
	@Override
	public String toString() {
		return this.x1 + " " + this.x2 + " " + StaticTransient.x3;
	}
}
